﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;

public enum DiskState
{
    Good,
    Warn,
    Fail
}


/// <summary>
/// Summary description for DiskInfo
/// </summary>
public class DiskInfo
{
    private DriveInfo _info;
    private long _warn;
    private long _fail;

    public long WarnLimit
    {
        get { return _warn; }        
    }

    public long FailLimit
    {
        get { return _fail; }
    }

    public long FreeSpace 
    {
        get { return _info.AvailableFreeSpace; }        
    }

    public long FreeSpaceMB
    {
        get { return FreeSpace / 1024 / 1024; }
    }

    public string FileSystem
    {
        get { return _info.DriveFormat; }
    }

    public string VolumeName
    {
        get { return _info.VolumeLabel; }
    }

    public string Root
    {
        get { return _info.RootDirectory.FullName; }
    }

    public double ProcentageFree
    {
        get { return ((double)_info.AvailableFreeSpace / (double)_info.TotalSize) * 100; }
    }

    public DiskState State
    {
        get
        {
            if (FreeSpaceMB <= FailLimit)
                return DiskState.Fail;
            if (FreeSpaceMB <= WarnLimit)
                return DiskState.Warn;
            return DiskState.Good;
        }
    }

    public DiskInfo(string letter, long warn, long fail)
    {
        _info = new DriveInfo(letter);
        _warn = warn;
        _fail = fail;        
    }
}
